//
//  ReportInfos.swift
//
//  Created by zwb on 2016/12/26
//  Copyright (c) aonong. All rights reserved.
//

import Foundation

open class ReportInfos: SwiftyJSONAble {

  // MARK: Declaration for string constants to be used to decode and also serialize.
  fileprivate let kReportInfosVersionNoKey: String = "version_no"
  fileprivate let kReportInfosInfosKey: String = "infos"
  fileprivate let kReportInfosFlagKey: String = "flag"

  // MARK: Properties
  open var versionNo: String?
  open var infos: [Report]?
  open var flag: String?

  // MARK: SwiftyJSON Initalizers
  /**
   Initates the instance based on the object
   - parameter object: The object of either Dictionary or Array kind that was passed.
   - returns: An initalized instance of the class.
  */
  convenience public init(object: Any) {
    self.init(json: JSON(object))
  }

  /**
   Initates the instance based on the JSON that was passed.
   - parameter json: JSON object from SwiftyJSON.
   - returns: An initalized instance of the class.
  */
  public required init(json: JSON) {
    versionNo = json[kReportInfosVersionNoKey].string
    if let items = json[kReportInfosInfosKey].array { infos = items.map { Report(json: $0) } }
    flag = json[kReportInfosFlagKey].string
  }

  /**
   Generates description of the object in the form of a NSDictionary.
   - returns: A Key value pair containing all valid values in the object.
  */
  open func dictionaryRepresentation() -> [String: Any] {
    var dictionary: [String: Any] = [:]
    if let value = versionNo { dictionary[kReportInfosVersionNoKey] = value }
    if let value = infos { dictionary[kReportInfosInfosKey] = value.map { $0.dictionaryRepresentation() } }
    if let value = flag { dictionary[kReportInfosFlagKey] = value }
    return dictionary
  }

}
